

#include <gtk/gtk.h>
#include "support.h"
#include "statusbar.h"
#include "page_state.h"

/*############### Define Globals ##################*/
GtkWidget *gsim_statusbar;
GtkWidget *gsim_progress;
gint status_context_id;

/*################ Update the status bar ####################*/
void gsim_update_statusbar(gint which,const gchar *text)
{
	static GString *file_str,*edit_str,*desc_str;
	static gint first_time=1;
	if(first_time)
	{
		file_str=g_string_new("");
		edit_str=g_string_new("");
		desc_str=g_string_new("");
		first_time=0;
	}
	gtk_statusbar_pop(GTK_STATUSBAR(gsim_statusbar),status_context_id);
	
	switch(which)
	{
		case FILE_SBAR:
			g_string_assign(file_str,_(" FILE:  "));
			g_string_append(file_str,text);
			if(save_state==0)
				g_string_append(file_str,_(" [Saved]"));
			else
				g_string_append(file_str,_(" [Unsaved]"));
			break;
		case EDIT_SBAR:
			g_string_assign(edit_str,_(" EDIT:  "));
			g_string_append(edit_str,text);
			break;
		case DESC_SBAR:
			g_string_assign(desc_str,_(" DESC:  "));
			g_string_append(desc_str,text);
			break;
		default:
			break;
	}
	
	GString *status_text;
	status_text=g_string_new("");
	g_string_append_printf(status_text,"%s      %s       %s",file_str->str,edit_str->str,desc_str->str);
	gtk_statusbar_push(GTK_STATUSBAR(gsim_statusbar),status_context_id,status_text->str);
	g_string_free(status_text,TRUE);
	
	return;
}

/*############# Make th status box of the app ###############*/
GtkWidget *gsim_get_status_box( void )
{
	GtkWidget *hbox;
	hbox=gtk_hbox_new(FALSE,0);
	
	/*Pack ProgressBar*/
	gsim_progress=gtk_progress_bar_new();
	gtk_box_pack_start(GTK_BOX(hbox),gsim_progress,FALSE,TRUE,0);
	
	/*pack statusbars in the box*/
	gsim_statusbar=gtk_statusbar_new( );
	status_context_id=gtk_statusbar_get_context_id(GTK_STATUSBAR(gsim_statusbar),"first");
	gtk_widget_set_size_request(gsim_statusbar,200,-1);
	gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(gsim_statusbar),TRUE);
	gtk_box_pack_start(GTK_BOX(hbox),gsim_statusbar,TRUE,TRUE,0);
	
	
	/*initlise every statusbar*/
	gsim_update_statusbar(FILE_SBAR," ");
	gsim_update_statusbar(DESC_SBAR," ");
	gsim_update_statusbar(EDIT_SBAR,_("Off"));
	
	/*pack everything in a frame*/
	GtkWidget *frame;
	frame=gtk_frame_new(NULL);
	gtk_container_add(GTK_CONTAINER(frame),hbox);
	gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_IN);
	
	return frame;
}
